//接口数据显示jsonview   http://localhost:8080/api/look
// const router = require("koa-router")();

const Router = require("koa-router")
const router = new Router();
// console.log(router instanceof Router);//config/index.js  requireDirectory
const MembersModel = require("../../models/Members")
// 查询数据库
router.post("/api/next",async ctx=>{
    // ctx.body = "api"
    var {id} = ctx.request.body;
    var data = await MembersModel.find({});
    var index = data.findIndex(item=>item._id == id);
    console.log(index);
    if(index == -1){
        ctx.body ={
            code:200,
            msg:"输入的参数不合法",
            request:"POST /api/next"
        }
    }else{
        var obj = data[index+1]
        ctx.body ={
            code:200,
            result:obj,
            msg:"下一条数据"
        }
    }
    
})
module.exports = router;